package A;

class Employee{

    private String title = "Employee ";

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return this.title;
    }

}

class Manager extends Employee{

    private String title = "Manager";

}

class Director extends Employee{

    private String title = "Director";

    public String getTitle() {
        return this.title;
    }
}

public class Deter {

    public static void main(String[] args) {

        Employee e = new Employee();
        Employee m = new Manager();
        Manager m2=new Manager();
        Director d = new Director();
        Employee d2 = new Director();
        System.out.println(d2.getTitle());

        System.out.println(e.getTitle());

        //子类Manager的getTitle方法继承于父类Employee，
        //因此调用时,访问的是父类的同名成员变量
        System.out.println(m.getTitle());
        System.out.println(m2.getTitle());
        //子类Director override父类的getTitle方法，
        //因此调用时，访问的是子类自己的成员变量
        System.out.println(d.getTitle());

        //子类Director的setTitle方法继承于父类Employee，
        //因此调用时，改变的是父类的同名成员变量
        d.setTitle("President");
        System.out.println(d.getTitle());

    }
}
